<?php
/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 * 
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 * 
 * Company website: http://www.x2engine.com 
 * Community and support website: http://www.x2community.com 
 * 
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license 
 * to install and use this Software for your internal business purposes.  
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong 
 * exclusively to X2Engine.
 * 
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/
$this->menu=array(
    array('label'=>'Sidebar Settings', 'url'=>array('settings?where=side'))
);
$model = new Dashboard;
$model = $model->search('dash');
$hideWidgetJs = '';
$ind = 1;
foreach ($model as $row){
    $class = $row['name'];
    $rowPLUS = $model[$ind+1];
    $classPLUS = $rowPLUS['name'];
    if ($row['showDASH'] == 0){
        $hideWidgetJs .= "$('#widget_" . $class . " .portlet-content').hide();\n";
        $hideWidgetJs .= "$('#widget_" . $classPLUS . " .portlet-content').css('float','right');\n";
    }
}
Yii::app()->clientScript->registerScript('blarg',"
    function blarg(){
        $.ajax({
            url:'" . CHtml::normalizeUrl(array('changeColumns')) . "',
            type: 'POST',
            data: $('#menu1').serialize(),
            update: '.blah',
            success: function(response){
                " . $hideWidgetJs . "
            }
        });
    }", CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScript('hideIntro', "
    function hideIntro(){
        $.ajax({
            url: '" . CHtml::normalizeUrl(array('hideIntro')) . "',
            update: '.intro',
            success: function(response){
                $('div.intro').hide();
            }
        });
    }", CClientScript::POS_HEAD);
$hINT = intval($hINT);
$hideIntro = CHtml::link('Hide Intro', '#', array('onclick'=>"hideIntro();","class"=>"hideIntro"));
if (!($hINT)){
?>
<div class="intro"><?php echo $hideIntro; ?>
<h2><center><?php echo Yii::t('charts','Widget Dashboard'); ?></center></h2>
<?php echo Yii::t('app','<center><p>Below you see a physical listing of your widgets. Please re-order and re-size them until you are satisfied.</br>The alterations you make to this page <b>DO NOT</b> change the default listing on the right side of your screen.</p></center>');?>
</div>
<?php 
}
echo CHtml::ajaxButton(
    "Dashboard Settings",
    $this->createUrl('dashSettings'),
    array('type'=>'POST','data'=>"item=$item"),
    array('class'=>'x2-button btn btn-mini  btn-yellow alterDASH')
);
?>
<div class="blah" id='large'>
<?php
$this->widget('SortWidg',array(
    'portlets'=>$model,
    'items'=>$item,
    'jQueryOptions'=>array(
        'opacity'=>0.6,
        'handle'=>'.portlet-decoration',
        'distance'=>20,
        'delay'=>150,
        'revert'=>50,
        'update'=>"js:function(){
            $.ajax({
                type: 'POST',
                url: 'widgetOrder',
                data: $('#yw0').sortable('serialize'),
            });
        }"
    ),
));
echo "</div>";
?>
